package com.zhuoshi.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.zhuoshi.entity.RoomCustom;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
@Component
public class ImportExecl {
	public List<RoomCustom> importExecl() throws Exception {
		// 1:创建workbook
		Workbook workbook = Workbook.getWorkbook(new File("d:/价格模板.xls"));
		// 2:获取第一个工作表sheet
		Sheet sheet = workbook.getSheet(0);
		// 3:获取数据
		// System.out.println("行："+sheet.getRows());
		// System.out.println("列："+sheet.getColumns());
		List<RoomCustom> roomCustoms = new ArrayList<RoomCustom>();
		for (int i = 1; i < sheet.getRows(); i++) {
			RoomCustom roomCustom = new RoomCustom();
			roomCustom.setId(Integer.parseInt(sheet.getCell(0, i).getContents()));
			roomCustom.setProjectname(sheet.getCell(1, i).getContents());
			roomCustom.setNumber(sheet.getCell(2, i).getContents());
			roomCustom.setArea(Float.parseFloat(sheet.getCell(4, i).getContents()));
			roomCustom.setRoomprice(Float.parseFloat(sheet.getCell(6, i).getContents()));
			roomCustom.setRoomtotal(Float.parseFloat(sheet.getCell(7, i).getContents()));
			roomCustoms.add(roomCustom);

			// for(int j=0;j<sheet.getColumns();j++){
			// Cell cell=sheet.getCell(j,i);
			// cell.getContents();
			// System.out.print(cell.getContents()+" ");
			// }
			// System.out.println();
		}

		// 最后一步：关闭资源
		workbook.close();
		return roomCustoms;
	}

}
